<%--
  Created by IntelliJ IDEA.
  User: 企鹅劳劳
  Date: 2023/6/4
  Time: 10:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
        }

        body {
            height: 100%;
        }

        .container {
            height: 100%;
            background-color: antiquewhite;
        }

        .big {
            background-image: linear-gradient(to right, #a9c4f2, rgb(173, 173, 173));
            width: 400px;
            height: 550px;
            border-radius: 50px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .header {
            font-size: 60px;
            font-weight: 900;
            text-align: center;
            line-height: 120px;
        }

        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128, 125, 125);
            font-size: 15px;
            outline: none;
        }


        .login {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-color: cornflowerblue;
            color: white;
        }

        .msg {
            text-align: center;
            line-height: 88px;
        }

        a {
            text-decoration-line: none;
            color: cornflowerblue;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="big">
        <div class="header">修改信息</div>
        <div class="header" style="font-size: 20px;line-height: 30px">请至少修改一项</div>
        <form id="form" class="form-wrapper" method="post" action="/modifyInfo">
            <input type="text" id="username" name="username" placeholder="请输入用户名" class="input-item">
            <input type="password" id="password" name="firstPassword" placeholder="请输入密码" class="input-item">
            <input type="password" id="password2" name="secondPassword" placeholder="请再次输入密码" class="input-item">
            <input type="email" id="email" name="email" placeholder="请输入邮箱" class="input-item">
        </form>
        <button class="login" onclick="regist()">修改</button>
        <div class="msg">
            放弃修改
            <a href="UserDetail.jsp">回去</a>
        </div>
    </div>
</div>
</body>
</html>
<script>
    regist = function () {
        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;
        var password2 = document.getElementById('password2').value;
        var email = document.getElementById('email').value;
        var num = /^\w+@[a-z0-9]+\.[a-z]+$/i;
        var form=document.getElementById('form');
        var cangive=true;
        if (username.length == 0 & password.length == 0 & email.length == 0) {//至少要有一项要修改
            alert('至少要修改一项');
            cangive=false;
        } else {
            if (password.length != 0) {//选择了修改密码
                if (password.length < 8 || password.length > 16) {
                    alert('密码长度错误');
                    cangive = false;
                } else {
                    if (password != password2) {
                        alert('前后密码不一致')
                        cangive = false;
                    }
                }
            }
            if(email.length!=0){//选择了修改邮箱
                if (num.test(email) == false) {
                    alert('电子邮箱格式错误')
                    cangive=false;
                }
            }
        }
        if(cangive){
            form.submit();
        }
    }
</script>
